import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class IMUReceiver {
    public static void main(String[] args) throws Exception {
        int port = 12345; // 监听端口
        byte[] buffer = new byte[1024];

        DatagramSocket socket = new DatagramSocket(port);
        System.out.println("UDP IMU Receiver started, listening on port " + port);

        while (true) {
            DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
            socket.receive(packet);

            // 假设IMU数据为字符串
            String imuData = new String(packet.getData(), 0, packet.getLength());
            System.out.println("Received IMU data: " + imuData);

            // 如果IMU数据为二进制结构体，可在这里解析buffer内容
        }
    }
}